import multiprocessing
import time

def fib(n):
    # Intentionally inefficient to highlight CPU work
    if n <= 1:
        return n
    return fib(n-1) + fib(n-2)

def testMultiprocessing(datas):
    # Create a pool of processes
    pool = multiprocessing.Pool(processes=4)
    results = pool.map(fib, datas)
    
    pool.close()
    pool.join()
    return results

def single_process(datas):
    results = []
    for n in datas:
        result = fib(n)
        results.append(result)
    return results

# n-values for which we want Fibonacci results
numbers = [30, 31, 32, 33, 34, 35, 36, 37, 38, 39]

def main():
    start_time = time.time()
    
    # use multiprocessing
    print("Use multiprocessing")
    start_time = time.time()
    print(f"Results: {testMultiprocessing(numbers)}")
    print(f"Total time: {time.time() - start_time:.2f} seconds")
    
    print("================================================")

    # use single process
    print("Use single process")
    start_time = time.time()
    print(f"Results: {single_process(numbers)}")
    print(f"Total time: {time.time() - start_time:.2f} seconds")

if __name__ == "__main__":   main()